/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package com.yuecai.modules.yc_footprint;


import com.yuecai.modules.yc_footprint.domain.YcFootprint;
import com.yuecai.modules.yc_footprint.service.YcFootprintService;
import com.yuecai.modules.yc_footprint.service.dto.YcFootprintQueryCriteria;
import com.yuecai.utils.SecurityUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
* @website https://el-admin.vip
* @author dm
* @date 2020-07-02
**/
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/yc-footprint")
public class YcFootprintController {

    private final YcFootprintService ycFootprintService;

    @GetMapping
    public ResponseEntity<Object> query(YcFootprintQueryCriteria criteria, Pageable pageable){
        String currentUsername = SecurityUtils.getCurrentUsername();
        criteria.setUserId(Long.valueOf(currentUsername));
        return new ResponseEntity<>(ycFootprintService.queryAll(criteria,pageable),HttpStatus.OK);
    }
    @GetMapping("/number")
    public ResponseEntity<Object> finCount(YcFootprintQueryCriteria criteria, Pageable pageable){
        String currentUsername = SecurityUtils.getCurrentUsername();
        criteria.setUserId(Long.valueOf(currentUsername));
        return new ResponseEntity<>(ycFootprintService.finCount(criteria,pageable),HttpStatus.OK);
    }

    @PostMapping
    public ResponseEntity<Object> create(@Validated @RequestBody YcFootprint resources){
        String currentUsername = SecurityUtils.getCurrentUsername();
        Long aLong = Long.valueOf(currentUsername);
        resources.setUserId(aLong);
        return new ResponseEntity<>(ycFootprintService.create(resources),HttpStatus.CREATED);
    }

}